package com.ffs.game;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.ffs.game.animation.AnimationManager;
import com.ffs.game.scene.GameScene;
import com.ffs.game.scene.SceneManager;
import com.ffs.game.scene.WelcomeScene;
import com.ffs.game.scene.control.SceneControl;
import com.ffs.game.scene.obj.MapObjectFactory;
import com.ffs.game.scene.obj.Monster;

/**
 * 启动类
 *
 * @author ffs80
 */
public class GameBootStrap extends Game {

    /**
     * 场景控制器
     */
    private SceneControl sceneControl;

    public static void main(String[] args) {
        LwjglApplicationConfiguration configuration = new LwjglApplicationConfiguration();
        configuration.width = 500;
        configuration.height = 400;
        configuration.resizable = false;
        new LwjglApplication(new GameBootStrap(), configuration);
    }

    @Override
    public void create() {
        AnimationManager.getInstance().initMonsterAnimation();
        Monster monster = MapObjectFactory.createMonster();
        Stage stage = new Stage();
        GameScene startScreen = new WelcomeScene(stage, 1);
        startScreen.addActor(monster);
        SceneManager.getInstance().addScene(startScreen);
        setScreen(startScreen);
    }

    @Override
    public void render() {
        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        GameScene scene = SceneManager.getInstance().findScene(1);
        if (scene == null) {
            return;
        }
        scene.draw();
    }
}
